package hasToMany

import (
	"context"
	"errors"
	v1 "gf-example/api/relationalQuery/v1"
	"gf-example/internal/dao"
	"gf-example/internal/service"
)

type sHasToMany struct {
}

func New() *sHasToMany {

	return &sHasToMany{}
}

func init() {
	service.RegisterHasToMany(New())
}

func (s *sHasToMany) FindByHasToMany(ctx context.Context) (out *v1.HasToManyRes, errs error) {
	//out = &v1.HasToManyRes{Content: &v1.HasToMany{}}
	mData := make([]*v1.HasToMany, 0)

	err := dao.Boyfriend.Ctx(ctx).Where(dao.Boyfriend.Columns().BoyfriendId, 1).WithAll().Scan(&mData)
	if err != nil {
		return nil, errors.New("查询一对多数据失败:" + err.Error())
	}
	return &v1.HasToManyRes{Content: mData}, nil
}
